<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/9/22 0022
 * Time: 17:23
 */

namespace App\Http\Controllers\Api;


use App\Models\GoodsCat;
use App\Models\Mb_CatImage;
use Illuminate\Http\Request;


class CatController extends Controller
{
    public function cat(Request $request){


        //获取右边的展示栏

       $catlist= GoodsCat::GoodsCat_list($request->input('cat_parent_id',0));

        $img_row = array();
        $datas=array();
       if(0==$request->input('cat_parent_id',0)){
           $cat_img_rows=Mb_CatImage::Mb_CatImagelist();

           $cat_img_rows->each(function ($cat_img_row,$index) use (&$img_row){
               $img_row[$cat_img_row->cat_id] = $cat_img_row->mb_cat_image;
           });
           $catlist->each(function ($item,$index) use (&$datas,&$img_row){
                if(isset($img_row[$item->cat_id])){
                    $item['cat_pic'] = $img_row[$item->cat_id];
                }
               $datas[] = $item;
           });
       }
       return $this->success($datas);
    }

    public function tree(Request $request){

        if(!empty($request->input('cat_parent_id'))){
           $s= GoodsCat::getChildCat($request->input('cat_parent_id',0));
           return $this->success($s);
        }
    }


}